package org.example.chatroom.common.config;

import org.example.chatroom.api.WebSocketApi;
import org.example.chatroom.common.config.TokenHandshakeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
* Created with IntelliJ IDEA.
* Description:
* User: LIUYANJIAO
* Date: 2025-06-29
* Time: 20:44
*/
@Configuration
@EnableWebSocket
public class WebSocketconfig implements WebSocketConfigurer {
    @Autowired
    private WebSocketApi webSocketApi;
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(webSocketApi,"/message")
                .setAllowedOrigins("*")
                .addInterceptors(new TokenHandshakeInterceptor());
    }
}
